﻿<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test Queuews</title>

<head>
    <script language="javascript" type="text/javascript">
        var refid = 0;
        var wsUri = "wss://ccctest.davco.cn/WSTCPMulticastGateway/websocket/queuews";
        var output;
        var websocket;
        function init() {
            output = document.getElementById("output");
            testWebSocket();
        }

        function testWebSocket() {

            websocket = new WebSocket(wsUri);

            websocket.onopen = function (evt) {
                onOpen(evt)
            };
            websocket.onclose = function (evt) {
                onClose(evt)
            };
            websocket.onmessage = function (evt) {
                onMessage(evt)
            };
            websocket.onerror = function (evt) {
                onError(evt)
            };

        }

        function onOpen(evt) {
            writeToScreen("CONNECTED");
        }

        function onClose(evt) {
            writeToScreen("DISCONNECTED");
        }

        function onMessage(evt) {
            writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
        }

        function onError(evt) {
            writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
        }

        function doSend(message) {
            websocket.send(message);
            writeToScreen("SENT: " + message);
        }

        function writeToScreen(message) {
            var pre = document.createElement("p");
            pre.style.wordWrap = "break-word";
            pre.innerHTML = message;
            output.appendChild(pre);
        }

        window.addEventListener("load", init, false);

        function TestBTS() {
            refid++;
            var srefid = "" + refid;
            var datas = { "module": "asyncbts", "refid": srefid, "op": "getfile", "mode": "ftp", "servername": "127.0.0.1", "endpoint": "21", "username": "max", "password": "letmein", "sourcefile": "c:\test.wav", "targetfile": "/test.wav", "binary": "true", "recursive": "true" };
            doSend(JSON.stringify(datas));
        }
        function TestLog() {
            //var content="测试日志记录:"+new Date();
            var content = ""
            for (var i = 0; i < 65534; i++) {
                content = content + "a";
            }

            doSend(content);
        }
    </script>
</head>

<body>
    <input type="button" value="测试BTS" onclick="TestBTS()"></input>
    <input type="button" value="测试Log" onclick="TestLog()"></input>
    <input type="button" value="关闭websocket" onclick="websocket.close()"></input>
    <h2>WebSocket Test</h2>
    <div id="output"></div>
</body>

</html>